package com.jiang.daily.Q3147;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/10/10 17:50
 */
class Solution {
    public int maximumEnergy(int[] energy, int k) {
        int res = Integer.MIN_VALUE;
        int len = energy.length;

        for (int i = k; i < len; i++) {
            if (energy[i - k] > 0) {
                energy[i] += energy[i - k];
            }
        }

        for (int i = len - k; i < len; i++) {
            res = Math.max(res, energy[i]);
        }
        return res;
    }
}
